package bsi.vn.FirstApp;

import java.util.Locale;

import bsi.vn.Lib.ProcessFunc;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

public class TicketFragmentActivity extends FragmentActivity {

	SectionsPagerAdapter mSectionsPagerAdapter;
	ViewPager mViewPager;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_ticket_fragment);

		mSectionsPagerAdapter = new SectionsPagerAdapter(
				getSupportFragmentManager());

		mViewPager = (ViewPager) findViewById(R.id.pager);
		mViewPager.setAdapter(mSectionsPagerAdapter);

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		 MenuInflater menuInflater = getMenuInflater();
	        menuInflater.inflate(R.menu.atmsearch, menu);
		return super.onCreateOptionsMenu(menu);
	}
	
	@Override
	public boolean onMenuItemSelected(int featureId, MenuItem item) {
		if(item.getItemId() != R.id.menu_ticket && item.getItemId() != R.id.menu_sub){
			startActivity(ProcessFunc.MenuAction(this, item));
		}
		return super.onMenuItemSelected(featureId, item);
	}

	public class SectionsPagerAdapter extends FragmentPagerAdapter {

		public SectionsPagerAdapter(FragmentManager fm) {
			super(fm);
		}

		@Override
		public Fragment getItem(int position) {
			Fragment fragment = new TicketSearchFragment(TicketFragmentActivity.this);
			switch(position)
			{
			case 0:
				fragment = new TicketListFragment(TicketFragmentActivity.this);
				break;
			case 1:
				fragment = new TicketSearchFragment(TicketFragmentActivity.this);
				break;
			case 2:
				fragment = new TicketResultSearchFragment(TicketFragmentActivity.this);
				break;
			}
			//Bundle args = new Bundle();
			//args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1);
			//fragment.setArguments(args);
			return fragment;
		}

		@Override
		public int getCount() {
			return 3;
		}

		@Override
		public CharSequence getPageTitle(int position) {
			Locale l = Locale.getDefault();
			switch (position) {
			case 0:
				return getString(R.string.tk_title_ProcessingTicket).toUpperCase(l);
			case 1:
				return getString(R.string.tk_title_TicketSearch).toUpperCase(l);
			case 2:
				return getString(R.string.tk_title_TicketResultSearch).toUpperCase(l);
			}
			return null;
		}
	}
}
